package com.design.graduation.asdemo.application;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.design.graduation.asdemo.dao.DaoMaster;
import com.design.graduation.asdemo.dao.DaoSession;
import com.design.graduation.asdemo.dao.HSFOpenHelper;
import com.igexin.sdk.PushManager;
import com.orhanobut.logger.AndroidLogTool;
import com.orhanobut.logger.LogLevel;
import com.orhanobut.logger.Logger;

import cn.smssdk.SMSSDK;


/**
 * Created by lijinyuan on 16/2/16.
 */
public class BaseApplication extends Application {

    private static BaseApplication instance;
    private DaoMaster mDaoMaster;
    private DaoSession mDaoSession;
    static {
        VersionConfigure.init();
    }

    @Override
    public void onCreate() {
        super.onCreate();
        instance = this;
        setupDatabase();

        SMSSDK.initSDK(this, "f9621cf77c83", "430fa29c79490124b2564e87f79dc4d6");

        Logger.init("AS_demo")                 // default PRETTYLOGGER or use just init()
                .methodCount(3)                 // default 2
                .hideThreadInfo()               // default shown
                .logLevel(Version.getDebugOrRelease().equals(Version.DebugOrRelease.DEBUG) ?
                        LogLevel.FULL : LogLevel.NONE)        // default LogLevel.FULL
                .methodOffset(2)                // default 0
                .logTool(new AndroidLogTool());
//        Fabric.with(this, new Crashlytics());
//        JPushInterface.setDebugMode(Version.getDebugOrRelease().equals(
//                DebugOrRelease.DEBUG));
//
//        RongIM.init(this);
//        RongCloudEvent.init(this);
//
//        MobclickAgent.openActivityDurationTrack(false);
//
//        /** 设置是否对日志信息进行加密, 默认false(不加密). */
//        AnalyticsConfig.enableEncrypt(Version.getDebugOrRelease().equals(
//                DebugOrRelease.RELEASE));

    }

    public static BaseApplication getInstance() {
        return instance;
    }

    public DaoSession getDaoSession() {
        return mDaoSession;
    }
    private void setupDatabase() {
        HSFOpenHelper helper = new HSFOpenHelper(this, "myDB.db", null);
        SQLiteDatabase database = helper.getWritableDatabase();
        mDaoMaster = new DaoMaster(database);
        mDaoSession = mDaoMaster.newSession();
    }

}
